1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
|
"use client";
import { useState, useEffect, useCallback, useMemo } from "react";
import { useParams } from "next/navigation";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Skeleton } from "@/components/ui/skeleton";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { InfoIcon, RefreshCw, Search, Upload, Plus, Loader2 } from "lucide-react";
import { toast } from "sonner";
import { useTranslation } from "@/i18n/client";
import {
UnifiedDwgReceiptItem,
DetailDwgReceiptItem,
FileInfoItem,
fetchDwgReceiptList,
getVendorSessionInfo,
fetchVendorProjects,
fetchDetailDwgReceiptList,
fetchFileInfoList,
deleteFileInfo,
} from "@/lib/dolce/actions";
import { DrawingListTableV2 } from "@/lib/dolce/table/drawing-list-table-v2";
import { drawingListColumns } from "@/lib/dolce/table/drawing-list-columns";
import { createGttDrawingListColumns, DocumentType } from "@/lib/dolce/table/gtt-drawing-list-columns";
import { createDetailDrawingColumns } from "@/lib/dolce/table/detail-drawing-columns";
import { createFileListColumns } from "@/lib/dolce/table/file-list-columns";
// V3: Sync 기능 없이 일괄 업로드 (MatchBatchFileDwg / Edit 사용)
import { B4BulkUploadDialogV3 } from "@/lib/dolce/dialogs/b4-bulk-upload-dialog-v3";
// V1로 되돌리려면: 위 줄을 주석 처리하고 아래 줄의 주석을 해제하세요
// import { B4BulkUploadDialog } from "@/lib/dolce/dialogs/b4-bulk-upload-dialog";
import { AddAndModifyDetailDrawingDialog } from "@/lib/dolce/dialogs/add-and-modify-detail-drawing-dialog";
import { UploadFilesToDetailDialog } from "@/lib/dolce/dialogs/upload-files-to-detail-dialog";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
interface DolceUploadPageV2Props {
searchParams: { [key: string]: string | string[] | undefined };
}
export default function DolceUploadPageV2({ searchParams }: DolceUploadPageV2Props) {
const params = useParams();
const lng = params?.lng as string;
const { t } = useTranslation(lng, "dolce");
// URL에서 초기 프로젝트 코드
const initialProjNo = (searchParams.projNo as string) || "";
// 상태 관리
const [drawings, setDrawings] = useState<UnifiedDwgReceiptItem[]>([]);
const [projects, setProjects] = useState<Array<{ code: string; name: string }>>([]);
const [vendorInfo, setVendorInfo] = useState<{
userId: string;
userName: string;
email: string;
vendorCode: string;
vendorName: string;
drawingKind: "B3" | "B4";
} | null>(null);
const [isLoading, setIsLoading] = useState(true);
const [isRefreshing, setIsRefreshing] = useState(false);
const [error, setError] = useState<string | null>(null);
// 필터 상태
const [projNo, setProjNo] = useState(initialProjNo);
const [drawingNo, setDrawingNo] = useState("");
const [drawingName, setDrawingName] = useState("");
const [discipline, setDiscipline] = useState("");
const [manager, setManager] = useState("");
const [documentType, setDocumentType] = useState<DocumentType>("ALL"); // B4 전용
// 선택된 도면 및 상세도면
const [selectedDrawing, setSelectedDrawing] = useState<UnifiedDwgReceiptItem | null>(null);
const [detailDrawings, setDetailDrawings] = useState<DetailDwgReceiptItem[]>([]);
const [selectedDetail, setSelectedDetail] = useState<DetailDwgReceiptItem | null>(null);
const [files, setFiles] = useState<FileInfoItem[]>([]);
const [isLoadingDetails, setIsLoadingDetails] = useState(false);
const [isLoadingFiles, setIsLoadingFiles] = useState(false);
// 다이얼로그
const [bulkUploadDialogOpen, setBulkUploadDialogOpen] = useState(false);
const [addDialogOpen, setAddDialogOpen] = useState(false);
const [dialogMode, setDialogMode] = useState<"add" | "edit">("add");
const [editingDetail, setEditingDetail] = useState<DetailDwgReceiptItem | null>(null);
const [uploadFilesDialogOpen, setUploadFilesDialogOpen] = useState(false);
// 파일 삭제 상태
const [fileToDelete, setFileToDelete] = useState<FileInfoItem | null>(null);
const [isDeletingFile, setIsDeletingFile] = useState(false);
// 초기 데이터 로드
const loadInitialData = useCallback(async () => {
try {
setIsLoading(true);
setError(null);
// 병렬로 데이터 로드
const [vendorInfoData, projectsData] = await Promise.all([
getVendorSessionInfo(),
fetchVendorProjects(),
]);
setVendorInfo(vendorInfoData as typeof vendorInfo);
setProjects(projectsData);
// 초기 프로젝트가 있으면 도면 로드
if (initialProjNo) {
const drawingsData = await fetchDwgReceiptList({
project: initialProjNo,
drawingKind: vendorInfoData.drawingKind,
drawingVendor: vendorInfoData.drawingKind === "B3" ? vendorInfoData.vendorCode : "",
});
setDrawings(drawingsData);
}
} catch (err) {
console.error("초기 데이터 로드 실패:", err);
setError(err instanceof Error ? err.message : t("page.initialLoadError"));
toast.error(t("page.initialLoadError"));
} finally {
setIsLoading(false);
}
}, [initialProjNo, t]);
// 도면 목록 조회
const loadDrawings = useCallback(async () => {
if (!projNo || !vendorInfo) return;
try {
setIsRefreshing(true);
setError(null);
const drawingsData = await fetchDwgReceiptList({
project: projNo,
drawingKind: vendorInfo.drawingKind,
drawingVendor: vendorInfo.drawingKind === "B3" ? vendorInfo.vendorCode : "",
});
setDrawings(drawingsData);
toast.success(t("page.drawingLoadSuccess"));
} catch (err) {
console.error("도면 로드 실패:", err);
setError(err instanceof Error ? err.message : t("page.drawingLoadError"));
toast.error(t("page.drawingLoadError"));
} finally {
setIsRefreshing(false);
}
}, [projNo, vendorInfo, t]);
// 상세도면 목록 로드
const loadDetailDrawings = useCallback(async () => {
if (!selectedDrawing) {
setDetailDrawings([]);
setSelectedDetail(null);
return;
}
try {
setIsLoadingDetails(true);
const data = await fetchDetailDwgReceiptList({
project: selectedDrawing.ProjectNo,
drawingNo: selectedDrawing.DrawingNo,
discipline: selectedDrawing.Discipline,
drawingKind: selectedDrawing.DrawingKind,
userId: "", // 조회 시 모든 사용자의 상세도면을 보기 위해 빈 문자열 전달
});
setDetailDrawings(data);
// 첫 번째 상세도면 자동 선택
if (data.length > 0) {
setSelectedDetail(data[0]);
} else {
setSelectedDetail(null);
}
} catch (error) {
console.error("상세도면 로드 실패:", error);
toast.error(t("detailDialog.detailLoadError"));
setDetailDrawings([]);
setSelectedDetail(null);
} finally {
setIsLoadingDetails(false);
}
}, [selectedDrawing, t]);
// 파일 목록 로드
const loadFiles = useCallback(async () => {
if (!selectedDetail) {
setFiles([]);
return;
}
try {
setIsLoadingFiles(true);
const data = await fetchFileInfoList(selectedDetail.UploadId);
setFiles(data);
} catch (error) {
console.error("파일 목록 로드 실패:", error);
toast.error(t("detailDialog.fileLoadError"));
setFiles([]);
} finally {
setIsLoadingFiles(false);
}
}, [selectedDetail, t]);
// 초기 데이터 로드
useEffect(() => {
loadInitialData();
}, [loadInitialData]);
// 프로젝트 변경 시 자동 검색
useEffect(() => {
if (projNo && vendorInfo) {
loadDrawings();
}
}, [projNo, vendorInfo, loadDrawings]);
// 선택된 도면 변경 시 상세도면 로드
useEffect(() => {
loadDetailDrawings();
}, [selectedDrawing, loadDetailDrawings]);
// 선택된 상세도면 변경 시 파일 목록 로드
useEffect(() => {
loadFiles();
}, [selectedDetail, loadFiles]);
// 도면 클릭 핸들러
const handleDrawingClick = (drawing: UnifiedDwgReceiptItem) => {
setSelectedDrawing(drawing);
};
// 검색 핸들러
const handleSearch = () => {
loadDrawings();
};
// 새로고침 핸들러
const handleRefresh = () => {
loadDrawings();
};
// 상세도면 새로고침 핸들러
const handleRefreshDetails = () => {
loadDetailDrawings();
};
// 파일 목록 새로고침 핸들러
const handleRefreshFiles = () => {
loadFiles();
};
// 일괄 업로드 완료 핸들러
const handleBulkUploadComplete = () => {
loadDrawings();
if (selectedDrawing) {
loadDetailDrawings();
}
};
// 상세도면 추가 완료 핸들러
const handleAddComplete = () => {
setAddDialogOpen(false);
loadDetailDrawings();
};
// 파일 업로드 완료 핸들러
const handleUploadComplete = () => {
setUploadFilesDialogOpen(false);
loadFiles();
// loadDetailDrawings();
};
// 파일 다운로드 핸들러
const handleDownload = async (file: FileInfoItem) => {
try {
toast.info(t("detailDialog.downloadPreparing"));
// 파일 생성자의 userId를 사용하여 다운로드
const response = await fetch("/api/dolce/download", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
fileId: file.FileId,
userId: file.CreateUserId, // 파일 생성자의 ID 사용
fileName: file.FileName,
}),
});
if (!response.ok) {
throw new Error(t("detailDialog.downloadError"));
}
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = file.FileName;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
toast.success(t("detailDialog.downloadSuccess"));
} catch (error) {
console.error("파일 다운로드 실패:", error);
toast.error(t("detailDialog.downloadError"));
}
};
// 상세도면 수정 핸들러
const handleEditDetail = (detail: DetailDwgReceiptItem) => {
setDialogMode("edit");
setEditingDetail(detail);
setAddDialogOpen(true);
};
// 파일 삭제 클릭 핸들러
const handleDeleteFileClick = (file: FileInfoItem) => {
setFileToDelete(file);
};
// 파일 삭제 확인 핸들러
const handleConfirmDeleteFile = async () => {
if (!fileToDelete) return;
try {
setIsDeletingFile(true);
await deleteFileInfo({
fileId: fileToDelete.FileId,
uploadId: fileToDelete.UploadId,
});
toast.success("File deleted successfully");
loadFiles();
} catch (error) {
console.error("파일 삭제 실패:", error);
toast.error("Failed to delete file");
} finally {
setIsDeletingFile(false);
setFileToDelete(null);
}
};
// 필터된 도면 목록 (클라이언트 사이드 필터링)
const filteredDrawings = useMemo(() => {
let result = drawings.filter((drawing) => {
// 도면번호 필터 (공백 포함)
if (drawingNo && !drawing.DrawingNo.toLowerCase().includes(drawingNo.toLowerCase())) {
return false;
}
// 도면명 필터 (공백 포함)
if (drawingName && !drawing.DrawingName.toLowerCase().includes(drawingName.toLowerCase())) {
return false;
}
// 설계공종 필터 (공백 포함)
if (discipline && !drawing.Discipline?.toLowerCase().includes(discipline.toLowerCase())) {
return false;
}
// 담당자명 필터 (공백 포함)
if (manager && !drawing.Manager.toLowerCase().includes(manager.toLowerCase()) &&
!drawing.ManagerENM?.toLowerCase().includes(manager.toLowerCase())) {
return false;
}
return true;
});
// B4인 경우 Document Type 필터 적용
if (vendorInfo?.drawingKind === "B4" && documentType !== "ALL") {
result = result.filter((drawing) => {
// B4 타입 체크
if (drawing.DrawingKind !== "B4") return false;
// B4 도면의 DrawingMoveGbn 체크
const gttDrawing = drawing as { DrawingMoveGbn?: string };
if (documentType === "SHI_INPUT") {
return gttDrawing.DrawingMoveGbn === "도면제출";
} else if (documentType === "GTT_DELIVERABLES") {
return gttDrawing.DrawingMoveGbn === "도면입수";
}
return true;
});
}
return result;
}, [drawings, drawingNo, drawingName, discipline, manager, vendorInfo?.drawingKind, documentType]);
// RegisterId + UploadId 조합으로 고유 ID 생성
const getDetailDrawingId = (detail: DetailDwgReceiptItem) => {
return `${detail.RegisterId}_${detail.UploadId}`;
};
// 도면 고유 ID 생성
const getDrawingId = (drawing: UnifiedDwgReceiptItem) => {
return `${drawing.ProjectNo}_${drawing.DrawingNo}_${drawing.Discipline}`;
};
// B4인 경우 "도면입수"인 건만 상세도면 추가 및 파일 첨부 가능
// B3인 경우 모든 건에 대해 가능
const canAddDetailDrawing = vendorInfo && (
vendorInfo.drawingKind === "B3" ||
(vendorInfo.drawingKind === "B4" && selectedDrawing && 'DrawingMoveGbn' in selectedDrawing && selectedDrawing.DrawingMoveGbn === "도면입수")
);
const canDeleteFile = selectedDetail?.Status === "Standby";
const fileColumns = createFileListColumns({
onDownload: handleDownload,
onDelete: canDeleteFile ? handleDeleteFileClick : undefined,
lng
});
if (isLoading) {
return (
<Card>
<CardHeader>
<Skeleton className="h-8 w-48" />
<Skeleton className="h-4 w-96" />
</CardHeader>
<CardContent className="space-y-4">
<Skeleton className="h-32 w-full" />
<Skeleton className="h-96 w-full" />
</CardContent>
</Card>
);
}
return (
<div className="space-y-4 max-w-full overflow-x-hidden h-full flex flex-col">
{/* 에러 메시지 */}
{error && (
<Alert variant="destructive">
<AlertDescription>{error}</AlertDescription>
</Alert>
)}
{/* 안내 메시지 */}
{!projNo && (
<Alert>
<InfoIcon className="h-4 w-4" />
<AlertDescription>
{t("page.selectProject")}
</AlertDescription>
</Alert>
)}
{/* 필터 카드 - 슬림하게 */}
<Card className="flex-shrink-0">
<CardHeader className="py-3">
<CardTitle className="text-base">{t("filter.title")}</CardTitle>
</CardHeader>
<CardContent className="py-3">
<div className="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-6 gap-3">
{/* 프로젝트 선택 */}
<div className="space-y-1">
<Label className="text-xs">{t("filter.project")}</Label>
<Select value={projNo} onValueChange={setProjNo}>
<SelectTrigger className="h-8">
<SelectValue placeholder={t("filter.projectPlaceholder")} />
</SelectTrigger>
<SelectContent>
{projects.map((project) => (
<SelectItem key={project.code} value={project.code}>
{project.code} - {project.name}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{/* 도면번호 검색 */}
<div className="space-y-1">
<Label className="text-xs">{t("filter.drawingNo")}</Label>
<Input
className="h-8"
value={drawingNo}
onChange={(e) => setDrawingNo(e.target.value)}
placeholder={t("filter.drawingNoPlaceholder")}
/>
</div>
{/* 도면명 검색 */}
<div className="space-y-1">
<Label className="text-xs">{t("filter.drawingName")}</Label>
<Input
className="h-8"
value={drawingName}
onChange={(e) => setDrawingName(e.target.value)}
placeholder={t("filter.drawingNamePlaceholder")}
/>
</div>
{/* 설계공종 검색 */}
<div className="space-y-1">
<Label className="text-xs">{t("filter.discipline")}</Label>
<Input
className="h-8"
value={discipline}
onChange={(e) => setDiscipline(e.target.value)}
placeholder={t("filter.disciplinePlaceholder")}
/>
</div>
{/* 담당자명 검색 */}
<div className="space-y-1">
<Label className="text-xs">{t("filter.manager")}</Label>
<Input
className="h-8"
value={manager}
onChange={(e) => setManager(e.target.value)}
placeholder={t("filter.managerPlaceholder")}
/>
</div>
{/* B4(GTT) 전용: Document Type 필터 */}
{vendorInfo?.drawingKind === "B4" && (
<div className="space-y-1">
<Label className="text-xs">{t("filter.documentType")}</Label>
<Select value={documentType} onValueChange={(value) => setDocumentType(value as DocumentType)}>
<SelectTrigger className="h-8">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="ALL">{t("filter.documentTypeAll")}</SelectItem>
<SelectItem value="GTT_DELIVERABLES">{t("filter.documentTypeGttDeliverables")}</SelectItem>
<SelectItem value="SHI_INPUT">{t("filter.documentTypeSHIInput")}</SelectItem>
</SelectContent>
</Select>
</div>
)}
</div>
<div className="flex gap-2 mt-3 justify-end">
<Button
size="sm"
onClick={handleSearch}
disabled={!projNo || isRefreshing}
>
<Search className="h-4 w-4 mr-2" />
{t("filter.searchButton")}
</Button>
{/* B4 벤더인 경우에만 일괄 업로드 버튼 표시 */}
{vendorInfo?.drawingKind === "B4" && (
<Button
size="sm"
variant="default"
onClick={() => setBulkUploadDialogOpen(true)}
disabled={!projNo || isRefreshing}
>
<Upload className="h-4 w-4 mr-2" />
{t("filter.bulkUploadButton")}
</Button>
)}
<Button
size="sm"
variant="outline"
onClick={handleRefresh}
disabled={!projNo || isRefreshing}
>
<RefreshCw className={`h-4 w-4 ${isRefreshing ? "animate-spin" : ""}`} />
</Button>
</div>
</CardContent>
</Card>
{/* 도면 리스트 테이블 - 항상 렌더링 */}
<Card className="flex-shrink-0 flex flex-col h-[45vh]">
<CardHeader className="py-3">
<CardTitle className="text-base">
{t("drawingList.title")}
{filteredDrawings.length > 0 && ` ${t("drawingList.count", { count: filteredDrawings.length })}`}
</CardTitle>
</CardHeader>
<CardContent className="p-0 flex-1 min-h-0 flex flex-col">
{!projNo || !vendorInfo ? (
<div className="flex items-center justify-center text-muted-foreground p-8 min-h-[300px]">
<div className="text-center">
<InfoIcon className="h-12 w-12 mx-auto mb-2 opacity-50" />
<p>{t("page.selectProject")}</p>
</div>
</div>
) : isRefreshing ? (
<div className="flex items-center justify-center min-h-[300px]">
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
</div>
) : (
<DrawingListTableV2
columns={
vendorInfo.drawingKind === "B4"
? (createGttDrawingListColumns({ documentType, lng, t }) as any)
: (drawingListColumns(lng, t) as any)
}
data={filteredDrawings}
onRowClick={handleDrawingClick}
selectedRow={selectedDrawing || undefined}
getRowId={getDrawingId}
minHeight="0"
/>
)}
</CardContent>
</Card>
{/* 하단: 상세도면리스트 + 파일리스트 - 항상 렌더링 */}
<div className="grid grid-cols-1 2xl:grid-cols-[60fr_40fr] gap-4 flex-shrink-0 h-[45vh]">
{/* 좌측: 상세도면 리스트 */}
<Card className="flex flex-col min-h-0 h-full 2xl:h-auto min-w-0">
<CardHeader className="flex-row items-center justify-between py-3 flex-shrink-0">
<CardTitle className="text-base">
{t("detailDialog.detailListTitle")}
{selectedDrawing && (
<span className="text-xs font-normal text-muted-foreground ml-2">
Drawing No: {selectedDrawing.DrawingNo}, Drawing Name: {selectedDrawing.DrawingName}, Discipline: {selectedDrawing.Discipline}
</span>
)}
</CardTitle>
<div className="flex gap-2">
<Button
variant="outline"
size="sm"
onClick={handleRefreshDetails}
disabled={!selectedDrawing || isLoadingDetails}
>
<RefreshCw className={`h-4 w-4 ${isLoadingDetails ? "animate-spin" : ""}`} />
</Button>
{canAddDetailDrawing && (
<Button
variant="default"
size="sm"
onClick={() => {
setDialogMode("add");
setEditingDetail(null);
setAddDialogOpen(true);
}}
disabled={!selectedDrawing}
>
<Plus className="h-4 w-4 mr-2" />
{t("detailDialog.addDetailButton")}
</Button>
)}
</div>
</CardHeader>
<CardContent className="flex-1 p-0 min-h-0">
{!selectedDrawing ? (
<div className="h-full flex items-center justify-center text-muted-foreground p-4 min-h-[300px]">
<div className="text-center">
<InfoIcon className="h-12 w-12 mx-auto mb-2 opacity-50" />
<p>Select a drawing</p>
</div>
</div>
) : isLoadingDetails ? (
<div className="flex items-center justify-center h-full min-h-[300px]">
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
</div>
) : (
<DrawingListTableV2<DetailDwgReceiptItem, unknown>
columns={createDetailDrawingColumns(lng, t, handleEditDetail)}
data={detailDrawings}
onRowClick={setSelectedDetail}
selectedRow={selectedDetail || undefined}
getRowId={getDetailDrawingId}
minHeight="0"
/>
)}
</CardContent>
</Card>
{/* 우측: 첨부파일 리스트 */}
<Card className="flex flex-col min-h-0 h-full 2xl:h-auto min-w-0">
<CardHeader className="flex-row items-center justify-between py-3 flex-shrink-0">
<CardTitle className="text-base">
{t("detailDialog.fileListTitle")}
{selectedDetail && (
<span className="text-xs font-normal text-muted-foreground ml-2">
Rev. {selectedDetail.DrawingRevNo}
</span>
)}
</CardTitle>
<div className="flex gap-2">
<Button
variant="outline"
size="sm"
onClick={handleRefreshFiles}
disabled={!selectedDetail || isLoadingFiles}
>
<RefreshCw className={`h-4 w-4 ${isLoadingFiles ? "animate-spin" : ""}`} />
</Button>
{selectedDetail && canAddDetailDrawing && (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<div className="inline-block">
<Button
variant="default"
size="sm"
onClick={() => setUploadFilesDialogOpen(true)}
// Status check: only allow upload if status is 'Standby'
disabled={selectedDetail.Status !== "Standby"}
>
<Upload className="h-4 w-4 mr-2" />
{t("detailDialog.uploadFilesButton")}
</Button>
</div>
</TooltipTrigger>
{selectedDetail.Status !== "Standby" && (
<TooltipContent>
<p>{t("detailDialog.uploadRestrictedStandby")}</p>
</TooltipContent>
)}
</Tooltip>
</TooltipProvider>
)}
</div>
</CardHeader>
<CardContent className="flex-1 p-0 min-h-0">
{!selectedDetail ? (
<div className="h-full flex items-center justify-center text-muted-foreground p-4 min-h-[300px]">
<div className="text-center">
<InfoIcon className="h-12 w-12 mx-auto mb-2 opacity-50" />
<p>{t("detailDialog.selectDetailDrawing")}</p>
</div>
</div>
) : isLoadingFiles ? (
<div className="flex items-center justify-center h-full min-h-[300px]">
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
</div>
) : (
<DrawingListTableV2
columns={fileColumns}
data={files}
minHeight="0"
/>
)}
</CardContent>
</Card>
</div>
{/* B4 일괄 업로드 다이얼로그 (V3) */}
{/* V3: Sync 기능 없이 일괄 업로드 (MatchBatchFileDwg / Edit 사용) */}
{vendorInfo && vendorInfo.drawingKind === "B4" && projNo && (
<B4BulkUploadDialogV3
open={bulkUploadDialogOpen}
onOpenChange={setBulkUploadDialogOpen}
projectNo={projNo}
userId={vendorInfo.userId}
userName={vendorInfo.userName}
userEmail={vendorInfo.email}
vendorCode={vendorInfo.vendorCode}
onUploadComplete={handleBulkUploadComplete}
lng={lng}
/>
)}
{/* V1로 되돌리려면: 위의 B4BulkUploadDialogV3를 B4BulkUploadDialog로 변경하세요 */}
{/* 상세도면 추가 다이얼로그 */}
{vendorInfo && selectedDrawing && (
<AddAndModifyDetailDrawingDialog
open={addDialogOpen}
onOpenChange={setAddDialogOpen}
drawing={selectedDrawing}
vendorCode={vendorInfo.vendorCode}
userId={vendorInfo.userId}
userName={vendorInfo.userName}
userEmail={vendorInfo.email}
onComplete={handleAddComplete}
drawingKind={vendorInfo.drawingKind}
lng={lng}
mode={dialogMode}
detailDrawing={editingDetail}
/>
)}
{/* 파일 업로드 다이얼로그 */}
{vendorInfo && selectedDetail && (
<UploadFilesToDetailDialog
open={uploadFilesDialogOpen}
onOpenChange={setUploadFilesDialogOpen}
uploadId={selectedDetail.UploadId}
drawingNo={selectedDetail.DrawingNo}
revNo={selectedDetail.DrawingRevNo}
userId={vendorInfo.userId}
onUploadComplete={handleUploadComplete}
lng={lng}
/>
)}
{/* 파일 삭제 확인 다이얼로그 */}
<AlertDialog open={!!fileToDelete} onOpenChange={(open) => !open && setFileToDelete(null)}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete File</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to delete this file? This action cannot be undone.
{fileToDelete && (
<div className="mt-2 p-2 bg-muted rounded-md text-sm font-medium">
{fileToDelete.FileName}
</div>
)}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={isDeletingFile}>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={handleConfirmDeleteFile}
disabled={isDeletingFile}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{isDeletingFile ? "Deleting..." : "Delete"}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
);
}
|